//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "FaureRsg.h"
using namespace Cephei::QL::Math::Randomnumbers;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Randomnumbers::CFaureRsg::CFaureRsg (UInt64 dimensionality) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phFaureRsg = NULL;
#endif
        QuantLib::Size _dimensionality = (QuantLib::Size)ValueHelper::Convert (dimensionality);
        _ppFaureRsg = new boost::shared_ptr<QuantLib::FaureRsg> (new QuantLib::FaureRsg ( _dimensionality ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Randomnumbers::CFaureRsg::CFaureRsg (boost::shared_ptr<QuantLib::FaureRsg>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phFaureRsg = NULL;
#endif
	_ppFaureRsg = &childNative;
    
}
Cephei::QL::Math::Randomnumbers::CFaureRsg::CFaureRsg (QuantLib::FaureRsg& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phFaureRsg = NULL;
#endif
	_ppFaureRsg = new boost::shared_ptr<QuantLib::FaureRsg> (&childNative);
    
    _FaureRsgOwner = owner;
    
}

Cephei::QL::Math::Randomnumbers::CFaureRsg::CFaureRsg (CFaureRsg^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phFaureRsg = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFaureRsg = new boost::shared_ptr<QuantLib::FaureRsg> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Randomnumbers::CFaureRsg::CFaureRsg (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phFaureRsg = NULL;
#endif
	if (!t->IsSubclassOf(CFaureRsg::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Randomnumbers::CFaureRsg::CFaureRsg (QuantLib::Handle<QuantLib::FaureRsg>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phFaureRsg = &childNative;
	_ppFaureRsg = &static_cast<boost::shared_ptr<QuantLib::FaureRsg>>(childNative.currentLink());
    
    _FaureRsgOwner = owner;
}
Cephei::QL::Math::Randomnumbers::CFaureRsg::CFaureRsg (QuantLib::Handle<QuantLib::FaureRsg> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phFaureRsg = &childNative;
	_ppFaureRsg = &static_cast<boost::shared_ptr<QuantLib::FaureRsg>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Randomnumbers::CFaureRsg::CFaureRsg (QuantLib::FaureRsg childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phFaureRsg = NULL;
#endif
	_ppFaureRsg = new boost::shared_ptr<QuantLib::FaureRsg> (new QuantLib::FaureRsg (childNative));
    
}
#endif

Cephei::QL::Math::Randomnumbers::CFaureRsg::~CFaureRsg ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppFaureRsg != NULL)
    {
	    delete _ppFaureRsg;
        _ppFaureRsg = NULL;
    }
}
Cephei::QL::Math::Randomnumbers::CFaureRsg::!CFaureRsg ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppFaureRsg != NULL)
    {
	    delete _ppFaureRsg;
    }
}
QuantLib::FaureRsg& Cephei::QL::Math::Randomnumbers::CFaureRsg::GetReference ()
{
    if (_ppFaureRsg == NULL) throw gcnew NativeNullException ();
	return **_ppFaureRsg;
}
boost::shared_ptr<QuantLib::FaureRsg>& Cephei::QL::Math::Randomnumbers::CFaureRsg::GetShared ()
{
    if (_ppFaureRsg == NULL) throw gcnew NativeNullException ();
	return *_ppFaureRsg;
}
QuantLib::FaureRsg* Cephei::QL::Math::Randomnumbers::CFaureRsg::GetPointer ()
{
    if (_ppFaureRsg == NULL) throw gcnew NativeNullException ();
	return &**_ppFaureRsg;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FaureRsg>& Cephei::QL::Math::Randomnumbers::CFaureRsg::GetHandle ()
{
	if (_phFaureRsg == NULL)
	{
		_phFaureRsg = new Handle<QuantLib::FaureRsg> (*_ppFaureRsg);
	}
	return *_phFaureRsg;
}
#endif
bool Cephei::QL::Math::Randomnumbers::CFaureRsg::HasNative () 
{
	return (_ppFaureRsg != NULL);
}

UInt64 Cephei::QL::Math::Randomnumbers::CFaureRsg::Dimension::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppFaureRsg)->dimension ( );   
        UInt64 _nrv = (UInt64)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Randomnumbers::IFaureRsg^ Cephei::QL::Math::Randomnumbers::CFaureRsg_Factory::Create (UInt64 dimensionality)
{
    return gcnew CFaureRsg ( dimensionality);
}
